Determining which index to create - Mailing list pgsql-general

From Eric Cholet
Subject Determining which index to create
Date
Msg-id 697886661.1006345387@[192.168.1.14]
Whole thread Raw
Responses Re: Determining which index to create
List pgsql-general
I have the following table :

 Attribute |           Type           | Modifier
-----------+--------------------------+----------
 motid     | integer                  | not null
 objid     | integer                  | not null
 date      | timestamp with time zone | not null

...with 140 million rows. For each distinct value of
motid there are many rows (with different objid/dates).
I would like to optimize the following query:

=> select * from dico_frs where motid=4742 order by date desc limit 10;

Creating an index on 'date' makes the query use that index:

Limit  (cost=0.00..17591.91 rows=10 width=16)
  ->  Index Scan Backward using dico_frs_date on dico_frs
(cost=0.00..20023641.63 rows=11382 width=16)

But it's still quite slow. I'm thinking an index on (motid, date desc)
would be best
but that doesn't seem to be possible. How can I optimize this query?

--
Eric Cholet


pgsql-general by date:

Previous
From: RoBSD
Date:
Subject: Re: NOTICE: (transaction aborted): queries ignored until END
Next
From: "Roman Havrylyak"
Date:
Subject: What size of block should I choose?